#include "string.h"

void string_test01()
{
    wanghao::string s("hello world");
    wanghao::string::iterator it = s.begin();
    //迭代器
    while(it != s.end())
    {
        cout << *it;
        it++;
    }
    cout << endl;
    //范围for
    for(const auto& e : s)
    {
        cout << e;
    }
    cout << endl;
    cout << s.size() << endl;
    cout << "字符串的长度:" << s.size() << endl;
    cout << "字符串是否为空:" << s.empty() << endl;
    cout << "字符串容量为:" << s.capacity() << endl;
    s.clean();
    cout << s.c_str() << endl;
}
void string_test02()
{
    const wanghao::string s("hello world");
    for(auto& e : s)
    {
        cout << e;
    }
    cout << endl;
    cout << "字符串的长度:" << s.size() << endl;
    cout << "字符串是否为空:" << s.empty() << endl;
    cout << "字符串容量为:" << s.capacity() << endl;
    cout << s.c_str() << endl;
}
void string_test03()
{
    wanghao::string s("hello");
    cout << s.c_str() << endl;
    s.pop_back();
    s.pop_back();
    s.pop_back();
    cout << s.c_str() << endl;
    s.pop_back();
    s.pop_back();
    s.pop_back();
    cout << s.c_str() << endl;

}
void string_test04()
{
    wanghao::string s("hello world");
    //范围for遍历
    for(auto& e : s)
    {
        cout << e;
    }
    cout << endl;
    s.erase(5,3);
    for(size_t i = 0;i < s.size();i++)
    {
        cout << s[i];
    }
    cout << endl;
    s[7] = 'W';
    cout << s.c_str() << endl;
    s.push_back('A');
    s.push_back('A');
    s.push_back('A');
    s.push_back('A');
    cout << s.c_str() << endl;
}
void string_test05()
{
    wanghao::string s1("hello world");
    getline(cin,s1,'W');
    cout << s1 << endl;
}
void string_test06()
{
    wanghao::string s1("hollo world");
    wanghao::string s2("hollo wo");
    cout << (s1 == s2) << endl;
    cout << (s1 != s2) << endl;
    cout << (s1 > s2) << endl;
    cout << (s1 < s2) << endl;
    cout << (s1 >= s2) << endl;
    cout << (s1 <= s2) << endl;
}
void string_test07()
{
    wanghao::string s1("hello world");
    wanghao::string s2("how are you");
    cout << s2 << endl;
    //取子串
    s2 = s1.substr(9,12);
    cout << s2 << endl;    
}
void string_test08()
{
    wanghao::string s("hello world");
    size_t find = s.find("wo",7);
    if(find != s.npos)
        cout << "找到了,下标是:" << find << endl;
    else
        cout << "没找到" << endl;
}
int main()
{
    string_test08();
    return 0;
}